<%@ page language="java" import="com.alibaba.fastjson.JSONObject" pageEncoding="UTF-8" %>
<%@ page import="weaver.conn.RecordSet" %>
<%@ page import="weaver.general.Util" %>
<%--根据物品名称获取总价--%>
<%
    JSONObject jsonData = new JSONObject();
    RecordSet rs = new RecordSet();
    rs.executeQuery("select wpmcll,wplb,sl from uf_stypfftz");
    while (rs.next()) {
        String wpmc = Util.null2String(rs.getString("wpmcll"));
        String wplb = Util.null2String(rs.getString("wplb"));
        int sl = Util.getIntValue(rs.getString("sl"));
        boolean flag = compZj(wpmc, sl, wplb);
        jsonData.put("wpmc", wpmc);
        jsonData.put("sl", sl);
        jsonData.put("flag", flag);
    }
    out.print(jsonData.toJSONString());
%>
<%!
    public static boolean compZj(String wpmc, int slsl, String wplb) {
        RecordSet rs = new RecordSet();
        double totalPrice = 0;
        int xslsl = slsl;
        int count;
        rs.executeQuery("select id,(isnull(ylysl,0)) sysl,dj from uf_styprktz " +
                "where wpmc=? and wplb=? and (sfsc is null or sfsc=1) and (sl-isnull(ylysl,0))>=0" +
                " order by rksj", wpmc, wplb);
        while (rs.next()) {
            int sysl = Util.getIntValue(rs.getString("sysl"));
            double dj = Util.getDoubleValue(rs.getString("dj"));
            count = xslsl - sysl;
            if (count > 0) {
                xslsl = xslsl - sysl;
                totalPrice += sysl * dj;//100
            } else {
                totalPrice += xslsl * dj;
                break;
            }
        }
        return rs.executeUpdate("update uf_stypfftz set zj=? where wpmcll=? and wplb=?", totalPrice, wpmc, wplb);
    }
%>






